var maxClassLev = 0;
var availClass = [false];
var infoFields = [['character_name', 'Character Name', 40],
                  ['player_name',    'Player Name'   , 40],
                  ['size',           'Size'          ,  3],
                  ['gender',         'Gender'        ,  3],
                  ['alignment',      'Alignment'     ,  4],
                  ['relig_deity',    'Religion/Deity', 12],
                  ['height',         'Height'        ,  6],
                  ['weight',         'Weight'        ,  5],
                  ['looks',          'Looks'         , 40]];

function createClassLev()
{
    maxClassLev += 1; 
    availClass[maxClassLev] = true;
    
	var ret = document.createElement('div');
        ret.setAttribute('class','inbl pad');
        ret.appendChild(createLabeledField('class' + maxClassLev, 'Class', '', 10, true, ''));
        ret.appendChild(createLabeledField('level' + maxClassLev, 'Level', '',  3, true, ''));
	
    var del = createActionBlank('delClassLevel', 'del');
        del.onclick = function (idx) { return function () { 
                          availClass[idx]=false; 
                          deleteFromContaining(ret); }; 
                      }(maxClassLev);
    
    var deldiv = document.createElement('div');
        deldiv.setAttribute('class', 'inbl pad');
        deldiv.innerHTML = '<br>';
        deldiv.appendChild(del);
        
        ret.appendChild(deldiv);
    
	return ret;    
}

function appendClassLev(p)
{ p.appendChild(createClassLev()); }

function createRaceECL()
{
	var ret = document.createElement('div');
        ret.setAttribute('class','inbl pad');
        ret.appendChild(createLabeledField('race',      'Race',    '', 10, true, ''));
        ret.appendChild(createLabeledField('level_adj', 'L. Adj.', '',  3, true, ''));

	return ret;    
}

function appendRaceECL(p)
{ p.appendChild(createRaceECL()); }

function constructNameTab()
{
    var add = createActionBlank('addClassLevel', 'add');
        add.onclick = function(){ p.insertBefore(createClassLev(), adddiv); };
        
    var adddiv = document.createElement('div');
        adddiv.setAttribute('class', 'inbl pad');
        adddiv.innerHTML = '<br>';
        adddiv.appendChild(add);
        
    var p  = document.getElementById('tab-name');
        if (p.lastChild && p.lastChild.className == 'endls') {
            p.removeChild(p.lastChild); }
        for (i in infoFields)
        {
            appendLabeledField(p, infoFields[i][0], infoFields[i][1], '', infoFields[i][2], true, '');
            if (i == 1)
            {
                p.appendChild(createListEnder());
                p.appendChild(adddiv);
                appendRaceECL(p);
                p.appendChild(createListEnder());
            }
        }
        p.appendChild(createListEnder());
}

/* function below to be generated by python */
%(populateNameTab)s
